/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package source;
import java.io.*;
/**
 *
 * @author Administrator
 */
public class DialogueList {
    private static int maxDialoguesPerNPC = 20;
    public static int[][] identifier = new int[NPCList.maxListedNPCs][maxDialoguesPerNPC];
    public static String[] dialogue = new String [NPCList.maxListedNPCs*maxDialoguesPerNPC];
    {
        int x = 0;
        while(x < NPCList.maxListedNPCs)
        {
            int y = 0;
            while(y > (maxDialoguesPerNPC - 1))
            {
                identifier[x][y] = (x*maxDialoguesPerNPC)+y;
                y++;
            }
            x++;
        }
        getDialogueList();
    }
    private boolean getDialogueList(){
        String line = "";
		String token = "";
		String token2 = "";
		String token2_2 = "";
		String[] token3 = new String[10];
		boolean EndOfFile = false;
		int ReadMode = 0;
		BufferedReader characterfile = null;
		try {
			characterfile = new BufferedReader(new FileReader("./config/dialogue.cfg"));
		} catch(FileNotFoundException fileex) {
			misc.println("config/dialogue.cfg: file not found.");
			return false;
		}
		try {
			line = characterfile.readLine();
		} catch(IOException ioexception) {
			misc.println("config/dialogue.cfg: error loading file.");
			return false;
		}
		while(EndOfFile == false && line != null) {
			line = line.trim();
			int spot = line.indexOf("=");
			if (spot > -1) {
				token = line.substring(0, spot);
				token = token.trim();
				token2 = line.substring(spot + 1);
				token2 = token2.trim();
				token2_2 = token2.replaceAll("\t\t", "\t");
				while (token2_2.contains("\t\t")){
					token2_2 = token2_2.replaceAll("\t\t", "\t");
				}
				token3 = token2_2.split("\t");
				if (token.equals("dialogue")) {
					dialogue[Integer.parseInt(token3[0])*20+Integer.parseInt(token3[1])] = token3[2];
                }
			} else {
				if (line.equals("[ENDOFDIALOGUELIST]")) {
					try { characterfile.close(); } catch(IOException ioexception) { }
					return true;
				}
			}
			try {
				line = characterfile.readLine();
			} catch(IOException ioexception1) { EndOfFile = true; }
		}
		try {
			characterfile.close();
		} catch(IOException ioexception){
			ioexception.printStackTrace();
		}
		return false;
    }
}
